// search - time limits out

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int n, m, k;
int ans = -1;
vector<vector<int>> pack(110, vector<int>(30));

void dfs(vector<int> &status, int tot, int ind) {
    if (ans != -1 && tot > ans) return;

    bool check = true;
    for (int i = 1; i <= m; i++)
        if (status[i] == 0) {
            check = false;
            break;
        }
    if (check) ans = ans == -1 ? tot : min(tot, ans);
    if (check || ind >= n) return;

    for (int i = ind + 1; i <= n; i++) {
        check = false;
        for (auto &it : pack[i]) {
            if (status[it] == 0) check = true;
            status[it]++;
        }
        if (check) dfs(status, tot + 1, i);
        for (auto &it : pack[i]) status[it]--;
        dfs(status, tot, i);
    }
}

int main() {
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            cin >> pack[i][j];
        }
    }
    vector<int> status(m + 1, 0);
    dfs(status, 0, 0);
    cout << ans;
}